package sicnu.cs.ich.security.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Component;
import sicnu.cs.ich.common.services.impl.RedisService;
import sicnu.cs.ich.security.security.provider.EmailAuthenticationProvider;
import sicnu.cs.ich.security.security.rest.EmailAuthenticationFilter;
import sicnu.cs.ich.security.security.rest.RestAuthenticationFailureHandler;
import sicnu.cs.ich.security.security.rest.RestAuthenticationSuccessHandler;
import sicnu.cs.ich.security.util.JwtUtil;

/**
 * @author CaiKe
 * @date 2021/11/10 18:17
 */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class SecurityEmailConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
//    private final UserDetailsService userDetailsService;
//    private final JwtUtil jwtUtil;
//    private final ObjectMapper objectMapper;
//    private final RedisService redisService;
//    private final DefaultMQProducer producer;
//
//    @Override
//    public void configure(HttpSecurity http) {
//        var filter = new EmailAuthenticationFilter(objectMapper);
//        filter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
//        filter.setAuthenticationSuccessHandler(new RestAuthenticationSuccessHandler(jwtUtil, objectMapper, producer));
//        filter.setAuthenticationFailureHandler(new RestAuthenticationFailureHandler(objectMapper));
//        filter.setFilterProcessesUrl("/email/login");
//        var provider = new EmailAuthenticationProvider(userDetailsService, redisService);
//        log.info("EMAIL登录开启");
//        http.authenticationProvider(provider)
//                .addFilterAfter(filter, UsernamePasswordAuthenticationFilter.class);
//    }
//}